<!DOCTYPE html>
<html>
<head>
    <title>${doctor.name} 医生</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="${doctor.name} 医生的个人信息">

    <link rel="stylesheet" href="${basePath}/css/weui.min.css">
    <link rel="stylesheet" href="${basePath}/css/jquery-weui.css">
    <link rel="stylesheet" href="${basePath}/css/demos.css">

</head>

<body ontouchstart class="detail">

<div class="page__bd">
    <div class="weui-panel weui-panel_access">
        <div class="weui-panel__bd">
            <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
                <div class="weui-media-box__hd">
                    <img src="${basePath}/icon.img?doctorId=${doctor.id?c}" alt="" style="width:65px;height:90px;">
                </div>
                <div class="weui-media-box__bd">
                    <h4 class="weui-media-box__title">
                        <strong>${doctor.name}</strong>
                    </h4>
                    <input type="hidden" id="doctorId" value="${doctor.id?c}"/>
                    <p class="weui-media-box__desc">${doctor.departmentName} ${doctor.titleName}</p>
                <#if (doctor.tags?size > 0)>
                    <p class="weui-media-box__desc">
                        <#list doctor.tags as tag>
                            <span class="hospital">${tag.text}</span>
                        </#list>
                    </p>
                </#if>
                </div>
            </a>
        </div>
    </div>


    <div class="weui-panel weui-panel_access">
        <div class="weui-panel__bd">
            <div class="weui-media-box weui-media-box_text">
                <h4 class="weui-media-box__title">个人简介</h4>
                <p class="weui-media-box__desc">${doctor.introduction}</p>
            </div>
        </div>
    </div>
</div>

<div class="button_sp_area">
    <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary notice" style="display: none;">
        <img src="${basePath}/images/notice.png" alt="" style="width: 15px;">关注
    </a>
    <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary noticed"  style="display: none;">
        <img src="${basePath}/images/noticed.png" alt="" style="width: 15px;">已关注
    </a>
<#list doctor.products as product>
    <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary product" id="${product.typeId}">${product.type}(￥${product.price?c})</a>
</#list>
</div>
<script src="${basePath}/js/jquery-2.1.4.js"></script>
<script src="${basePath}/js/fastclick.js"></script>
<script src="${basePath}/js/jquery-weui.js"></script>
<script>
    var notice="${notice}";
    $(function () {
        FastClick.attach(document.body);
        if(parseInt(notice)==1){
            $('.noticed').show();
            $('.notice').hide();
        }else{
            $('.notice').show();
            $('.noticed').hide();
        }
    });
    $(document).on("click", ".product", function () {
        var e=$(this)[0];
        $.ajax({
            type: "get",
            async: false,
            url: '${basePath}/isPerfect.json',
            data: {},
            success: function (data) {
                if(data){
                    showOrderModal(e);
                }else{
                    showPerfectModal(e);
                }
            }
        });
    });

    function showPerfectModal(e){
        var typeId = e.id;
        var doctorId = $('#doctorId').val();
        var title = e.innerHTML;
        $.modal({
            title: title,
            text: '<div class="weui-cells weui-cells_form" style="margin-top:0px;"><div class="weui-cell">'+
            '<div class="weui-cell__hd"><label class="weui-label" style="color: black;text-align: left;">联系电话</label></div>'+
            '<div class="weui-cell__bd">'+
            '<input class="weui-input" type="tel" id="cellphone" name="cellphone" placeholder="请输入联系电话" value="${currentCustomer.cellphone!}">'+
            '</div></div></div>'+
            '<div class="weui-cells weui-cells_form" style="margin-top:0px;">'+
            '<div class="weui-cell weui-cell_switch">'+
            '<div class="weui-cell__bd" style="color: black;text-align: left;">所属医疗机构</div>'+
            '</div><div class="weui-cell" style="border: 1px solid #d9d9d9;"><div class="weui-cell__bd">'+
            '<input class="weui-input" type="text" id="clinic" name="clinic" placeholder="请输入机构名称" value="${currentCustomer.clinic!}">'+
            '</div></div><div class="weui-cell weui-cell_switch">'+
            '<div class="weui-cell__bd" style="color: black;text-align: left;">地址</div>'+
            '</div><div class="weui-cell" style="border: 1px solid #d9d9d9;"><div class="weui-cell__bd">'+
            '<input class="weui-input" type="text" id="address" name="address" placeholder="请输入机构所在地" value="${currentCustomer.address!}">'+
            '</div></div><div class="weui-cell weui-cell_switch">'+
            '<div class="weui-cell__bd" style="color: black;text-align: left;">简介</div>'+
            '</div><div class="weui-cell" style="border: 1px solid #d9d9d9;"><div class="weui-cell__bd">'+
            '<textarea class="weui-textarea" id="introduction" name="introduction" placeholder="请输入机构简介" rows="3">${currentCustomer.introduction!}</textarea>'+
            '</div></div></div>',
            buttons: [
                {text: "确认", onClick: function () {

                    var cellphone=$("#cellphone").val();
                    if(cellphone.length==0){
                        $.toast("联系电话不能为空", "forbidden");
                        return false;
                    }
                    var clinic=$("#clinic").val();
                    if(clinic.length==0){
                        $.toast("机构名称不能为空", "forbidden");
                        return false;
                    }
                    var address=$("#address").val();
                    if(address.length==0){
                        $.toast("机构所在地不能为空", "forbidden");
                        return false;
                    }
                    var introduction=$("#introduction").val();
                    var data={
                        cellphone: cellphone,
                        clinic: clinic,
                        address: address,
                        introduction: introduction
                    }
                    $.ajax({
                        type: "post",
                        async: false,
                        url: '${basePath}/updateCustomerTwo.json',
                        contentType: "application/x-www-form-urlencoded; charset=utf-8",
                        data: data,
                        success: function (data) {
                            $.toast("用户信息已保存!");
                            window.setTimeout(showOrderModal(e),1000);
                        }
                    });
                }},
                {text: "取消", className: "default"},
            ]
        });

    }

    function showOrderModal(e){
        var typeId = e.id;
        var doctorId = $('#doctorId').val();
        var title = e.innerHTML;
        $.modal({
            title: title,
            text: '<p class="weui-prompt-text">备注</p><textarea type="text" class="weui-input weui-prompt-input" id="memo" value="" style="margin: 10px 0px 0px; height: 83px; width: 231px;"></textarea>',
            buttons: [
                {text: "确认", onClick: function () {
                    $.ajax({
                        type: "post",
                        async: false,
                        url: '${basePath}/addOrder.json',
                        contentType: "application/x-www-form-urlencoded; charset=utf-8",
                        data: {
                            doctorId: doctorId,
                            typeId: typeId,
                            memo: $("#memo").val()
                        },
                        success: function (data) {
                            $.toast("预约成功!");
                            window.setTimeout(turnPayPage(data.t),1000);
                        }
                    });
                }},
                {text: "取消", className: "default"},
            ]
        });

    }

    function turnPayPage(order){
        var orderId=order.id;
        window.location.href =  '${basePath}/payOrder.htm?orderId='+orderId;
    }

    $(document).on("click", ".notice", function () {
        var doctorId = $('#doctorId').val();
        $.ajax({
            type: "get",
            async: false,
            url: '${basePath}/addNotice.json',
            data: {
                doctorId: doctorId
            },
            success: function (data) {
                $('.noticed').show();
                $('.notice').hide();
                $.toast("关注成功!");
            }
        });
    });
    $(document).on("click", ".noticed", function () {
        var doctorId = $('#doctorId').val();
        $.ajax({
            type: "get",
            async: false,
            url: '${basePath}/deleteNotice.json',
            data: {
                doctorId: doctorId
            },
            success: function (data) {
                $('.notice').show();
                $('.noticed').hide();
                $.toast("关注已取消!");
            }
        });
    });
</script>

</body>
</html>
